package com.lanou3g.ptp.message.mapper;

import com.lanou3g.ptp.entity.Message;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface MessageMapper {
    @Insert("INSERT INTO `message`(student_id,task_id,`type`,`title`,`content`,create_time,update_time,`status`) " +
            "VALUES(#{studentId},#{taskId},#{type},#{title},#{content},#{createTime},#{updateTime},#{status})")
    int insert(Message message);

    @Update("UPDATE `message` SET `status`=1,update_time=NOW() " +
            "WHERE student_id=#{studentId} AND `type`=#{type}")
    int readMessageByStudentIdAndType(@Param("studentId") Long studentId, @Param("type") Integer type);

    @Select("SELECT * FROM `message` WHERE student_id=#{studentId} AND `status`=0 ORDER BY create_time DESC")
    List<Message> findNotReadMsgByStudentId(Long studentId);
}
